import Vue from 'vue'
import Router from 'vue-router'
import PageOpen from './views/PageOpen.vue'
import animation from './views/Animation'

Vue.use(Router)

Router.prototype.goTo = function(miva, router, params) {
  const view = document.querySelector('#app')
  view.scrollTo(0, 0)
  console.log(router)
  // miva.$router.replace({ name: router })
  miva.$router.replace({ name: router, query: { ...params }})
  console.log('进入%s路由', router)
}

const router = new Router({
  // mode: 'history',
  base: process.env.BASE_URL,
  routes: [
    {
      path: '/',
      name: 'animation',
      component: animation
    },
    {
      path: '/open',
      name: 'open',
      component: PageOpen
    },
    // 小恩爱路由组
    {
      path: '/enai',
      name: 'enai',
      component: () => import(/* webpackChunkName: "PageEnai" */ './views/PageEnai')
    },
    {
      path: '/enai2',
      name: 'enai2',
      component: () => import(/* webpackChunkName: "PageEnai2" */ './views/PageEnai2')
    },
    {
      path: '/enai3',
      name: 'enai3',
      component: () => import(/* webpackChunkName: "PageEnai3" */ './views/PageEnai3')
    },
    // 单身狗路由组
    {
      path: '/dog',
      name: 'dog',
      component: () => import(/* webpackChunkName: "PageDog" */ './views/PageDog')
    },
    {
      path: '/dog2',
      name: 'dog2',
      component: () => import(/* webpackChunkName: "PageDog2" */ './views/PageDog2')
    },
    {
      path: '/dog3',
      name: 'dog3',
      component: () => import(/* webpackChunkName: "PageDog3" */ './views/PageDog3')
    },
    {
      path: '/dog4',
      name: 'dog4',
      component: () => import(/* webpackChunkName: "PageDog4" */ './views/PageDog4')
    }
  ]
})

// router.beforeEach((to, from, next) => {
//   console.log(window.miva)
//   if (window.miva == false) {
//     next({ path: '/' })
//     window.miva = true
//     console.log(window.miva)
//   } else {
//     next()
//   }
// })

export default router
